package com.ebupt.migu.common.push;

import org.apache.kafka.common.serialization.Serializer;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author liuyangyang@e-byte.com
 * @description: TODO
 * @date 2024/8/17 18:48
 */
public class PushTopicSerializer implements Serializer<PushTopicBean> {

    /**
     * Convert {@code data} into a byte array.
     *
     * @param topic topic associated with data
     * @param data  typed data
     * @return serialized bytes
     */
    @Override
    public byte[] serialize(String topic, PushTopicBean data) {
        try {
            if (data == null) {
                return null;
            }
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper.writeValueAsBytes(data);
        } catch (Exception e) {
            throw new IllegalArgumentException("Error serializing MyMessage", e);
        }
    }
}
